package com.landinfo.domain;

import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * The Region entity.
 * 行政区划实体
 */

/**
 * Region entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "t_region")
public class Region implements Serializable {

  // Fields

  private String id;
//  private Region parent;
  private String name;
  private Integer state;
  private Integer level;
//  private String parentid;
  private Set<Region> children = new LinkedHashSet<Region>();

  // Constructors

  /**
   * default constructor
   */
  public Region() {
  }


  // Property accessors
  @Id
  //@GeneratedValue
  @Column(name = "id", unique = true, nullable = false)
  public String getId() {
    return this.id;
  }

  public void setId(String id) {
    this.id = id;
  }

//  @ManyToOne(fetch = FetchType.LAZY)
//  @JoinColumn(name = "parentid")
//  public Region getParent() {
//    return this.parent;
//  }
//
//  public void setParent(Region parent) {
//    this.parent = parent;
//  }

  @Column(name = "name")
  public String getName() {
    return this.name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @Column(name = "state")
  public Integer getState() {
    return this.state;
  }

  public void setState(Integer state) {
    this.state = state;
  }

  @Column(name = "level")
  public Integer getLevel() {
    return level;
  }

  public void setLevel(Integer level) {
    this.level = level;
  }

//  @Column(name = "parentid")
//  public String getParentid() {
//    return parentid;
//  }
//
//  public void setParentid(String parentid) {
//    this.parentid = parentid;
//  }


  @Where(clause = "state=1")
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinColumn(name="parentid")
  @OrderBy(value = "id")
  public Set<Region> getChildren() {
    return this.children;
  }

  public void setChildren(Set<Region> children) {
    this.children = children;
  }



//  public String getParentid() {
//    return parentid;
//  }
//
//  public void setParentid(String parentid) {
//    this.parentid = parentid;
//  }
}
